package dbPicasso::Config;

use YAML qw(freeze thaw);
use IO::AtomicFile;

our %CONFIG;

&load;

sub load
{
	if (open CONFIG, "<$ENV{HOME}/.dbpicasso" )
	{
		my @cfgfile = <CONFIG>;
		my $cfgfile = join("", @cfgfile);
		close CONFIG;

		%CONFIG = %{thaw($cfgfile)};
	}
	else
	{
		%CONFIG = ();
	}
}

sub save
{
	my $cfgfile = freeze(\%CONFIG);

	my $CFG =  IO::AtomicFile->open("$ENV{HOME}/.dbpicasso", 'w');
	print $CFG $cfgfile;
	$CFG->close;;
}

sub get_section
{
	my $class = shift;
	my $section = shift;

	$CONFIG{$section} = {} unless (ref($CONFIG{$section}));

	return $CONFIG{$section};
}


1;
